package com.zhongxi.guoyuan.adapter.ad;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStore.HotGoodsData;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.GlideRoundTransform;

import java.util.List;

/**
 * Created by Administrator on 2016/11/2.
 */

public class JDMoreAdapter extends BaseAdapter {

    private List<HotGoodsData> datas;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public JDMoreAdapter(Context context, List<HotGoodsData> datas) {
        this.datas = datas;
        mLayoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView==null){
            convertView = mLayoutInflater.inflate(R.layout.ad_coin_item, parent, false);
            holder = new ViewHolder();
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tvCoinTitle);
            holder.tvDesc = (TextView) convertView.findViewById(R.id.tvShopName);
            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCoin);
            holder.tvOrign = (TextView) convertView.findViewById(R.id.tvOriginPrice);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivStoreImg);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=datas.get(position)&&!"".equals(datas.get(position))){
            HotGoodsData list = datas.get(position);
            if(null!=list.getThumbnail()&&!"".equals(list.getThumbnail())){
//                ImageLoader.getInstance().displayImage(Url.IMG_URL+list.getThumbnail(), holder.ivImg, CommonTool.getOptions(R.mipmap.iv_eg));
                Glide.with(context).load(Url.IMG_URL+list.getThumbnail()).placeholder(R.mipmap.iv_eg).transform(new GlideRoundTransform(context, 20)).into(holder.ivImg);
            }
            if(null!=list.getSubject()&&!"".equals(list.getSubject())){
                holder.tvDesc.setText(list.getSubject());
            }else{
                holder.tvDesc.setText("");
            }
            if(null!=list.getName()&&!"".equals(list.getName())){
                holder.tvTitle.setText(list.getName());
            }else{
                holder.tvTitle.setText("");
            }
            if(null!=list.getMarketprice()&&!"".equals(list.getMarketprice())){
                holder.tvOrign.setText(list.getMarketprice()+"元");
            }else{
                holder.tvOrign.setText("*元");
            }
            if(null!=list.getPrice()&&!"".equals(list.getPrice())){
                holder.tvCash.setText(list.getPrice());
            }else{
                holder.tvCash.setText("*");
            }
        }

        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvTitle;
        private TextView tvDesc;
        private TextView tvCash;
        private TextView tvOrign;
    }
}
